package com.wkq.jdbctemplate.commons;



import java.util.Date;
import java.util.Map;

/**
 * Created by yuj-b on 2017/1/9.
 */
public class RecordBuilder {

    private Record record = new Record();

    public RecordBuilder put(String key, Object value) {
        record.put(key,value);
        return this;
    }

    public RecordBuilder putIf(String key, Object value, boolean condition) {
        if (condition) {
            record.put(key,value);
        }
        return this;
    }

    public RecordBuilder putAll(Map<? extends String, ?> map) {
        record.putAll(map);
        return this;
    }

    public RecordBuilder putIgnoreNullValue(String key, Object value) {
        if (value!=null){
            record.put(key,value);
        }
        return this;
    }

    public RecordBuilder putCreateTime(){
        record.put("createTime", new Date());
        return this;
    }

    public RecordBuilder putTenantId(){
        record.put("tenantId", SessionCtx.tid());
        return this;
    }

    public Record build() {
        return record ;
    }

}
